<template>
	<view class="container" :class="'theme-'+theme">
		<view class="mp-search-box">

			<view class="searchBox">
				<view class="">
					<text>购物车({{countSku}})</text>
					<text @click="navToSearch('/pages/address/address')">
					<text class="eticon eticon-dingwei themeTextColor"></text>
<!--                         <image src="../../static/newh5/address.png"
                        class="yticon" style="width: 14px;height: 17px;margin-left:5px"></image> -->

					</text>
				</view>
				<view class="">
					<text>配送至：{{addrData.areaName}}</text>
				</view>

				<!-- <view class="inputBox" style="">
					<input class="ser-input"  @click="navToSearch('/pages/search/search')" type="search" placeholder-class="ph" placeholder="搜索" @confirm="toSearch" />
				</view> -->

			</view>
		</view>
		<view v-if="!hasLogin" class="empty">
			<view style="text-align: center;">
				<image src="/static/emptyCart.jpg" mode="aspectFit"></image>
			</view>
			<view class="empty-tips">
				空空如也
				<text class="navigator" @click="navToLogin">去登录></text>
			</view>
		</view>
		<view v-if="hasLogin" >
			<view v-if="cartLoading" class="loading-container">
				<u-loading size="36" />
			</view>
			<!-- 空白页 -->
			<view v-if="productData.length == 0 &&invalidGoods.length==0" class="empty">
				<view style="text-align: center;">
					<image src="/static/emptyCart.jpg" mode="aspectFit"></image>
				</view>
				<view  class="empty-tips">
					空空如也
					<text class="navigator" @click="toIndex">随便逛逛</text>
				</view>
			</view>
			<view v-else>
				<!-- 列表 -->
				<view class="cart-list">
					<block v-for="(item,index) in productData" :key="index">
						<view class="c-item" v-if="item.cartProducts.length>0">
							<view class="protocol-box" v-if="item.cartProducts.length>0&&supplierInfoShow">
							<view class="protocol-box-left">

								<image class="logo" src="../../static/store.png" mode="aspectFill" />
								<text class="protocol" @click="jumpStore(item)">{{item.name + ' '}}{{item.protocolName }}</text>

								<u-image v-if="item.protocolType == 'eplus' && item.cartItemLogo != ''"
									:src="item.cartItemLogo" width="100rpx" height="50rpx"></u-image>
							</view>
							<view class="protocol-box-right" style="margin-left: 8upx">
                <template v-if="showFreightConf">
								<view class="supplierNames singleLineText " :title="item.showInfo" v-if="showFreightConf && item.showInfo && item.showInfo=='已免运费'">{{item.showInfo}}</view>
                <view class="supplierNames singleLineText " :title="item.showInfo" v-if="showFreightConf && item.showInfo && item.showInfo!='已免运费'" style="color: red" >{{item.showInfo}}</view>
                </template>
                <template v-else>
                  <span class="supplierNames singleLineText " :title="'已免运费'" v-if="item.freight == 0">已免运费</span>
                  <span class="supplierNames singleLineText " v-else>
                  <span class="supplierNames singleLineText " :title="'已免运费'" v-if="item.freight - item.checkedSubtotal <= 0">已免运费</span>
                  <span class="supplierNames singleLineText " style="color:#ff0000;" :title="'还差¥'+(item.freight - item.checkedSubtotal)+'免运费'" v-if="item.freight - item.checkedSubtotal > 0">还差¥{{item.freight - item.checkedSubtotal}}免运费</span>
                </span>
                </template>
							</view>

							</view>
							<!-- 新购物车 -->
							<!-- <view class="main">
							<view
							    v-for="(children, key) in csListArrl"
							    :key="key"
							    :data-index="key"
							    class="order-item"
							    @touchstart="drawStart($event,item.cartProducts)"
							    @touchmove="drawMove($event,'111')"
							    @touchend="drawEnd($event,'111')"
							    :style="'right:'+children.right+'px'">
							        <view class="content">
										列表展示内容

									</view>
							        <view class="remove" @click="delData(item)">添加收藏</view>
							        <view class="edit" @click="editData(item)">删除</view>
							    </view>
							</view> -->
							<!-- @click="dianji2($event,children, index, key)" -->
							<u-swipe-action
							    :show="children.show"
							    :disabled="swipeAction"
							    btn-width="130"
							    :index="key"
							    v-for="(children, key) in item.cartProducts"
							    :key="key+'-'+index"
							    @open="actionOpen($event,item,children,key,index)"
							    :options="children.isCollection?optionsDelete:options"
								 @click = "onClick"
							>
							<!-- @click.stop="navToDetail(children)" -->
							<!-- $u.throttle(deleteCartItem(children,index,key,$event), 2000) -->
							<view class="wrapper" >
							<view class="cart-item">
								<view class="image-container">
									<image :src="children.thumbnail" @error="children.thumbnail = errorImgUrl"
										mode="aspectFill"></image>
									<view class="yticon icon-xuanzhong2 checkbox"
										:class="{checked: children.checked}" @click.stop="check('item',index,key)">
									</view>
								</view>
								<view class="item-right">

									<view class="title more-t" @click.stop="navToDetail(children)">{{children.name}}</view>
									<text class="price">￥{{children.originalPrice| money}}</text>
									<!-- <template v-if="children.checked">
										<view v-if="children.realPrice!=children.originalPrice" class="discount">
											<text style="margin-right: 4rpx;">优惠价:</text>
											<text>￥{{children.realPrice| money}}</text>
										</view>
									</template> -->
									<view v-if="(children.firstAddPrice != null) && (children.originalPrice < children.firstAddPrice)" style="color:red;vertical-align:middle;">距加入降￥{{parseFloat(children.firstAddPrice - children.realPrice).toFixed(2)}}</view>

									<view class="uni-num-box">
										<view class="subtract"
											style="border-top-left-radius: 10rpx;border-bottom-left-radius: 10rpx;"
											:class="{disabled:children.num<=1}"
											@click.stop="editNum(0,children.num,index,key)">-</view>
										<!--										 @click.stop="NumBtn('reduce',index,key)">-</view>-->

										<input class="count" type="number" v-model:value="children.num"
											@click.stop="stopPrevent()"
											@blur="editInputNum($event,index,key,children.num)"
											@confirm="editInputNum($event,index,key,children.num)" />

										<view class="add"
											style="border-top-right-radius: 10rpx;border-bottom-right-radius: 10rpx;"
											:class="{disabled: children.num>99999999}"
											@click.stop="editNum(1,children.num,index,key)">+</view>

										<!-- <text>{{children.show}}</text> -->
										<view class="stack" v-if="notRemainGoods.hasOwnProperty(children.id)">库存不足
										</view>
										<view class="stack"
											v-if="(!notRemainGoods.hasOwnProperty(children.id)) && (children.moq != null) && (children.num < children.moq) && (children.num >= 0)">
											未到起订量</view>
									</view>
								</view>
							</view>
							<view class="a-section" v-if="children.activity&&children.activity.type">
								<view class="a-tit">参与活动：</view>
								<view style="display: flex;">
									<template v-if="children.activity&&children.activity.type===1">
										<text class="activity" v-for="(rule,ruleIndex) in children.activity.ruleList" :key="rule.id">
										{{rule.num}}件{{rule.discount}}折
										</text>
									</template>
								</view>
							</view>
							</view>
							</u-swipe-action>
							<!-- 旧购物车 -->
						<!-- 	<view class="wrapper" @click="navToDetail(children)"
								v-for="(children, key) in item.cartProducts" :key="key+'-'+index" :id="children.id">
								<view class="cart-item">
									之前注释内容
									 :class="{'b-b': key!==item.cartProducts.length-1}">
									<view class="image-container">
										<image :src="children.thumbnail" @error="children.thumbnail = errorImgUrl"
											mode="aspectFill"></image>
										<view class="yticon icon-xuanzhong2 checkbox"
											:class="{checked: children.checked}" @click.stop="check('item',index,key)">
										</view>
									</view>
									<view class="item-right">
										<view class="title more-t">{{children.name}}</view>
										<text class="price">￥{{children.realPrice| money}}</text>
										<view class="uni-num-box">
											<view class="subtract"
												style="border-top-left-radius: 10rpx;border-bottom-left-radius: 10rpx;"
												:class="{disabled:children.num<=1}"
												@click.stop="editNum(0,children.num,index,key)">-</view>
												之前注释内容
											@click.stop="NumBtn('reduce',index,key)">-</view>
											<input class="count" type="number" v-model:value="children.num"
												@click.stop="stopPrevent()"
												@blur="editInputNum($event,index,key,children.num)"
												@confirm="editInputNum($event,index,key,children.num)" />

											<view class="add"
												style="border-top-right-radius: 10rpx;border-bottom-right-radius: 10rpx;"
												:class="{disabled: children.num>99999999}"
												@click.stop="editNum(1,children.num,index,key)">+</view>


											<view class="stack" v-if="notRemainGoods.hasOwnProperty(children.id)">库存不足
											</view>
											<view class="stack"
												v-if="(!notRemainGoods.hasOwnProperty(children.id)) && (children.moq != null) && (children.num < children.moq) && (children.num >= 0)">
												未到起订量</view>

										</view>
									</view>
									<text class="del-btn yticon icon-fork"
										@click.stop="deleteCartItem(children,index,key)"></text>
								</view>
							</view>
 -->

						</view>
					</block>
				</view>

				<view v-if="invalidGoods.length>0">
					<text
						style="font-size: 15px;margin-left: 16px;font-weight: bold;">失效商品{{invalidGoods.length}}件</text>
					<text class="invalid-btn" @click="clearInvalid">清空失效商品</text>
					<block v-for="(item, index) in invalidGoods" :key="item.id">
						<view class="c-item" style="padding-top: 0;">
							<view class="cart-item" style="padding: 16rpx;"
								:class="{'b-b': index!==invalidGoods.length-1}">
								<view class="image-wrapper">
									<image :src="item.thumbnail" :class="[item.loaded]" mode="aspectFill" lazy-load
										@load="onImageLoad('invalidGoods', index)"
										@error="onImageError('invalidGoods', index)"></image>
										<image v-if="item.status=='soldout'"  :class="[item.loaded,'soldout']" src="../../static/outOfStock1.png" mode="aspectFill" lazy-load/>
								</view>
								<view class="item-right">
									<text class="title more-t" style="color: #909399;">{{item.name}}</text>
									<!-- <text class="attr">{{item.catalogName}}</text> -->
									<text class="price" style="color: #909399;">￥{{item.price| money}}</text>
									<text class="clamp title" style="margin-top: 50upx;color: #909399;">
										{{item.status==='unsale'?'商品已下架，无法购买':(item.status==='invalid'?'商品已失效，无法购买':'商品已售罄，无法购买')}}
									</text>
								</view>
								<text class="del-btn yticon icon-fork" @click="deleteInvalidItem(item,index)"></text>
							</view>
						</view>
					</block>
				</view>
			</view>
		</view>
		<template v-if="recommendList.length>0">
			<view style="margin-top: 20rpx;font-size: 26rpx;font-weight: 700;color: #333;text-align: center;">为您推荐以下商品</view>
			<hot-goods :data="recommendList" :hasLogin="hasLogin" :isShowPriceUnlogin="isShowPriceUnlogin"></hot-goods>
		</template>
		<!-- 底部菜单栏 -->
		<view class="action-section" v-if="hasLogin">
			<view class="checkbox">
				<image :src="allChecked?'/static/selected.png':'/static/select.png'" mode="aspectFit"
					@click="check('all')"></image>
				<view class="clear-btn" :class="{show: allChecked}" @click="clearCart">
					清空
				</view>
			</view>
			<!-- <view class="total-box-left"> -->
				<view class="total-box">
					<view>
						<text class="price" v-if="empty">￥0.00</text>
						<template v-else>
							<text>已选{{checkedNum}}件，合计：</text>
							<text class="price">￥{{totalsum| twoBitMoney}}</text>
						</template>
					</view>
				<!-- 	<view class="coupon">
						共优惠:￥
						<text v-if="empty">0.00</text>
						<template v-else>
							<text>{{jieyueTotalSum | twoBitMoney}}</text>
							<text v-if="jieyueTotalSum>0" @click="showDiscount = true" style="margin-left: 10rpx;">查看明细</text>
						</template>
					</view> -->
				</view>
				<button type="primary" class="no-border confirm-btn" @click="createOrder">去结算</button>
			<!-- </view> -->
		</view>
		<!-- <u-popup v-model="showDiscount" mode="bottom" height="70%" closeable>
			<cart-discount :data="productData" :total="totalsum" :discount="jieyueTotalSum"></cart-discount>
		</u-popup> -->
	</view>
</template>

<script>
	// import CartDiscount from '../../components/marketing/cartDiscount.vue'
	import {
		errorImgUrl,

	} from '@/common/utils/config.js';
	import {

		getBatchOrderConfFreight
	} from '@/api/conf/conf.js'
	import {
		mapState
	} from 'vuex';
	//收藏夹功能接口
	import {
		addCollection,
		removeCollection,
		favorites
	} from '@/api/product/list.js'
	import {
		order,
	} from '../../common/utils/config';
	import {
		getAddressList,
		deleteAddr,
		qryGuessHotGoods,
		queryDefinedHotGoods
	} from '../../api/order/order.js'
	import {
		countCart
	} from '@/api/index/index';
	import {
		cart,
		remove,
		edit,
		checkChange,
		checkSkip,
		addGoodCart,
	} from '../../api/cart/cart.js'
	import {
		accMul,
		accAdd,
		accSub,
		filterTwoBitMoney,
		filterMoney
	} from '../../common/utils/func'
	import uniNumberBox from '@/components/uni-number-box.vue'
  import {showRuleSupplierInfoShow, qryConfByItemCode} from '@/api/user/user.js'
  import {
  	jugdeShopSetting
  } from '../../api/hotStores/hotStores.js'

	import HotGoods from '@/components/hot-goods/hot-goods.vue'
	export default {
		components: {
			uniNumberBox,
			HotGoods,
			// CartDiscount
		},
		data() {
			return {
				// showDiscount:false,
				checkedNum:0,
				//商品大类
				selectedProducts:{},
				productIndex:'',
				productKey:'',
				//选中当前购物车内容
				selectedGoods:'',
				//购物车收藏内容
				csListArrl:[
					{
							name:'小A',
							age:'18',
							right: 0
						},
						{
								name:'小b',
								age:'15',
								right: 0
							},
						],
				//左滑默认宽度
				delBtnWidth: 120,
				swipeAction: false, //是否禁止滑动
				options: [
					{
					    text: '添加收藏',
					    style: {
					        backgroundColor: '#FFCC33',


					    }
					},
				    {
				        text: '删除',
				        style: {
				            backgroundColor: '#FD013E'
				        }
				    },

				],
				optionsDelete: [
					{
					    text: '取消收藏',
					    style: {
					        backgroundColor: '#fe7f02',


					    }
					},
				    {
				        text: '删除',
				        style: {
				            backgroundColor: '#FD013E'
				        }
				    },

				],
				favoritesList:[],
				addrPage: 1,
				addrData: {},
				//购物车配置分隔
				cartLoading: true,
				totalsum: 0, //总价格
				allChecked: false, //全选状态  true|false
				empty: false, //空白页现实  true|false
				cartList: [],
				productData: [],
				checkAlls: false,
				//购物车商品临时列表
				cartTemData:[],
				//失效商品列表
				invalidGoods: [],
				invalidCount: 0,
				invalidMaps: {},
				// 存储库存不足商品
				notRemainGoods: {},
				errorImgUrl: errorImgUrl,
				jieyueTotalSum: 0,
				productActivity: {},
				productCurrentActivity: {},
				isConsistent: false,
				checkedList: [],
				supplierInfoShow: true,
				// 华润-是否开启打样单
				sampleApplication: false,
                firstLoad: true,
				countSku:0,
				showFreightConf:false,
				isShowPriceUnlogin: uni.getStorageSync('isShowPriceUnlogin')||0,
				recommendList:[]
			};
		},
		onShow() {
			this.cartLoading = false;
			if (this.hasLogin){
				this.getCartData();
				setTimeout(() => this.getfavorites(), 1000);
				// this.getfavorites()
				this.freshIcons()
			}

		},
		watch: {
			//显示空白页
			productData(e) {
				let empty = e.length === 0 ? true : false;
				if (this.empty !== empty && this.invalidGoods.length === 0) {
					this.empty = empty;
				}
			}
		},
		computed: {
			...mapState(['hasLogin'])
		},
		onShow(){
			// this.loadAddrList()
			this.getfavorites()
			this.getCartData();
			this.freshIcons();
			this.getQueryDefinedHotGoods()
		},
		onLoad(option) {
			// this.source = option.source;
			this.loadAddrList()
			// this.getfavorites()
			// this.getCartData();
			// this.freshIcons()
			this.getConf()
			this.loadSupplierInfoShow()
		},
		methods: {
			getQueryDefinedHotGoods() {
				if(this.hasLogin){
					qryGuessHotGoods({current:1,end:10}).then(res=>{
						if(res.code===0){
							if(res.data&&res.data.length>0){
								res.data.forEach(item=>{
									if(item.goodsImageList&&item.goodsImageList.length>0){
										item.goodsImage = item.goodsImageList[0].url
									}
								})
								this.recommendList = res.data
							}
						}
					})
				}else{
					queryDefinedHotGoods({
						specialAreaId:2,
						goodsNum:10
					}).then(res => {
						if(res.code == 0) {
							this.recommendList = res.data
						}
					})
				}
			},
			//跳转到热门供应商
			jumpStore(item) {
				console.log(item)
				jugdeShopSetting({
					id: item.supplierId
				}).then(res => {
					if (res.code == 0) {
						if (JSON.stringify(res.data) != '{}') {
							uni.navigateTo({
								url: `/pages/hotList/hotStore?id=${res.data.supplierId}`
							})
						} else {
							this.$util.msg('该供应商无店铺')
						}
					}
				})
			},
			loadBatchOrderConfFreight() {
				console.log('this.productData', this.productData)
				              // 收集数据
				              let reqList = []
				              for(let i=0; i<this.productData.length; i++) {

				                let orderAmount = 0
								const checkedProducts = this.productData[i].cartProducts.filter(item=>item.status==='onsale'&&item.checked)
								if(checkedProducts.length>0)
				                checkedProducts.every(p=>orderAmount+=Number((p.num*p.price).toFixed(2)))
				                if (orderAmount == 0) {
				                  continue
				                }
				                reqList.push({
				                  areaId: uni.getStorageSync('areaId'),
				                  orderAmount: orderAmount,
				                  supplierId: this.productData[i].supplierId,
				                })
				              }
				getBatchOrderConfFreight(reqList).then(response => {
					 if (response.code == 0) {
					                  }
					                  let map = response.data
					                  // 赋值数据
					                  for(let i=0; i<this.productData.length; i++) {
										  console.log( this.productData[i])
					                    let orderAmount = this.productData[i].checkedSubtotal
					                    let supplierId = this.productData[i].supplierId
					                    let freightConf = {}
					                    let showInfo = ''

					                    if (orderAmount != 0 && map[supplierId]) {
					                      let freightConf = map[supplierId]
					                      this.showFreightConf = freightConf.distributionRuleIsEnabled
					                      showInfo = freightConf.showInfo
					                    }
					                    // this.productData[i].freightConf = freightConf
					                    this.$set(this.productData[i],'showInfo',showInfo)
					                  }
				})
			},
			getConf(){
				const deptInfo = uni.getStorageSync('deptinfo')[0]
				qryConfByItemCode({code: "sample_application",
					tenant_id: deptInfo.tenantId,
					dept_code: deptInfo.deptCode}).then(res=>{
						if(res.code===0){
							this.sampleApplication = res.data.val == '1'
						}
				})
			},
			checkSample(){
				let flag = false
				for (let index in this.productData) {
					let product = this.productData[index]
					if(product.cartProducts.filter(item=>item.checked).length>0&&product.protocolType=='supply'){
						flag = true
						break
					}
				}
				return flag
			},
			  // 获取是否屏蔽供应商信息配置
			  async loadSupplierInfoShow() {
				await showRuleSupplierInfoShow().then(res => {
				  if (res.code === 0) {
					this.supplierInfoShow = !res.data;
				  }
				})
			  },
			//取消收藏
			removeOne(val) {
				const param = {
					product_id: val
				}
				removeCollection(param).then(res => {
					if (res.code === 0) {
						this.$util.msg('取消收藏成功')
						this.selectCollectGoods(2)
						// this.deleteGoods(val)
						// this.favoriteList.splice(index, 1)
					} else {
						this.$util.msg(res.message)
					}
				})
			},
			//关注列表商品过滤
			filterFavorites(){
				this.favoritesList.forEach(item=>{
					this.productData.forEach(pitem => {
							pitem.cartProducts.forEach(product => {
								if(product.id == item)product.isCollection = true;
						})
					})
				})
			},
			//获取关注列表
			getfavorites(){
				favorites().then(res=>{
					if(res.code == 0){
						console.log('返回信息',res.data);
						this.favoritesList = JSON.parse(JSON.stringify(res.data))
						if(this.favoritesList.length!=0){
							console.log('this.favoritesList',this.favoritesList);
							this.filterFavorites();
						}
					}
				})
			},
			//加载收货地址列表
			loadAddrList() {
				const params = {
					page: this.addrPage,
					limit: 10
				}
				getAddressList(params).then(res => {
					if (res.code === 0) {
						if (res.data.records.length>0) {
							this.addrData = res.data.records[0];
							console.log('收货地址',this.addrData);
						}
					} else {
						this.toast(res.message)
					}
				})
			},
			// 删除
			actionClick(index, del) {
			    this.showModal = true;
			    this.delId = del;
			},
			// 删除确认
			confirm() {
			    let _self = this;
			    let delArr = [],
			        type = _self.btnType,
			        items = _self.cartList;
			    if (type === 'edit') {
			        delArr.push(_self.delId);
			    } else {
			        items.forEach(val => {
			            if (val.check) {
			                delArr.push(val._id);
			            }
			        });
			        _self.btnType = 'edit';
			    }

			    // 为了模拟清空购物车
			    if (delArr.length == items.length) {
			        _self.cartList = [];
			    }

			    _self.$refs.uToast.show({
			        title: '删除了id为' + delArr + '的商品',
			        icon: false
			    });
			},
			// 如果打开一个的时候，不需要关闭其他，则无需实现本方法
			actionOpen(index,item,children,key,indexs) {
				console.log('indexs',indexs);
				this.productIndex = indexs
				console.log('key',key);
				console.log('index',index)
				console.log('商品大类',item)
				console.log('children',children);
				this.selectedProducts = item
				this.productKey = key
				this.selectedGoods = children.id
			    // 先将正在被操作的swipeAction标记为打开状态，否则由于props的特性限制，
			    // 原本为'false'，再次设置为'false'会无效
			    let items = item.cartProducts
				// // item.show = true
			    items[index].show = true;
			    items.forEach((val, idx) => {
			        if (index != idx) {
			            items[idx].show = false;
			        }
			    });

			},

			//开始触摸滑动
				drawStart(e,val) {
					console.log("开始触发"+val);
					var touch = e.touches[0];
					this.startX = touch.clientX;
				},
				//触摸滑动
				drawMove(e,list) {
					console.log("滑动");
					for (var index in this.csListArrl) {
						this.$set(this.csListArrl[index],'right',0);
					}
					var touch = e.touches[0];
					var item = this.csListArrl[e.currentTarget.dataset.index];
					var disX = this.startX - touch.clientX;
					if (disX >= 20) {
					        if (disX > this.delBtnWidth) {
						    disX = this.delBtnWidth;
					        }
					        this.$set(this.csListArrl[e.currentTarget.dataset.index],'right',disX);
					} else {
						this.$set(this.csListArrl[e.currentTarget.dataset.index],'right',0);
					}
				},
				//触摸滑动结束
				drawEnd(e) {
					console.log("滑动结束");
					var item = this.csListArrl[e.currentTarget.dataset.index];
					if (item.right >= this.delBtnWidth / 2) {
						this.$set(this.csListArrl[e.currentTarget.dataset.index],'right',this.delBtnWidth);
					} else {
						this.$set(this.csListArrl[e.currentTarget.dataset.index],'right',0);
					}
				},
				//删除方法
				delData(item){
					console.log("删除")
					uni.showModal({
					    title: '提示',
					    content: "确认注销该人员？",
					    success: function (res) {
						if (res.confirm) {
							console.log('用户点击确定');
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					    }
					});
				},
				editData(item){
					uni.showModal({
						title: '提示',
						content: "确认编辑该项目？",
						success: function (res) {
							if (res.confirm) {
								console.log('用户点击确定');
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				},
			//-------
			navToSearch(url) {
				uni.navigateTo({
					url
				})
			},
			getCartData() {
				this.cartLoading = true;
				const params = {
					areaId: uni.getStorageSync('areaId'),
					catalogIds: '',
					purchaserId: uni.getStorageSync('deptinfo')[0].deptId
				}
				cart(params).then(res => {
					if (res.code !== 0) {
						this.$util.msg(res.message)
						return;
					}
					//res.data.resultGoodsList !== undefined
					//返回查询成功商品和 失效商品
					if (res.code === 0 && res.data.resultGoodsList !== undefined) {
						this.setCartInfo(res)
						console.log('商品内容截取',this.productData);

						this.productData.forEach((item, index) => {
							console.log('productData item',item)
							item.cartProducts.forEach((product, key) => {
								//增加 show属性来适配购物车的滑动
								this.$set(product,'show',false)
								this.$set(product,'isCollection',false)
								// product.show = false
								if (product.thumbnail === '' || product.thumbnail.startsWith('/'))
									product.thumbnail = '/static/errorImage.jpg';

							})
							this.filterFavorites()
						})
						console.log('productData',this.productData);
						this.getTotalsum()
						// this.loadBatchOrderConfFreight()
						if(this.firstLoad){
							this.firstLoad = false;
							if(res.data.cartNumLimitTip && res.data.cartNumLimitTip == '1'){
							  this.$util.msg("购物车已经满啦，如需加购新商品请清理后再进行添加！");
							}
						}
					} else {
						this.empty = true;
					}
					this.cartLoading = false
				})
			},
			toast(msg) {
				uni.showToast({
					title: msg,
					duration: 1200,
					mask: false,
					icon: 'none'
				});
			},
			// 获得购物车的初始属性
			setCartInfo(response) {
				let failGoodsList = response.data.failGoodsList
				let resultGoodsList = response.data.resultGoodsList
				let invalidMaps = response.data.invalidMaps
				let allChecked = response.data.allChecked
				this.checkAlls = allChecked
				this.invalidGoods = failGoodsList
				this.invalidCount = failGoodsList.length
				this.productData = resultGoodsList
				this.invalidMaps = invalidMaps
				this.notRemainGoods = invalidMaps
				 this.countSku = 0;
				      for(let i = 0;i<this.productData.length;i++){
				        this.countSku += this.productData[i].count;
				      }

				console.log('invalidGoods',this.invalidGoods);
			},
			//监听image加载完成
			onImageLoad(key, index) {
				this.$set(this[key][index], 'loaded', 'loaded');
			},
			//监听image加载失败
			onImageError(key, index) {
				this[key][index].thumbnail = '/static/errorImage.jpg';
			},
			navToLogin() {
				uni.navigateTo({
					url: '/pages/public/login'
				})
			},
			toIndex() {
				uni.switchTab({
					url: '../index/index'
				})
			},
			//选中状态处理
			check(type, index, key) {
				if (type === 'item') {
					const products = this.productData[index].cartProducts
					const param = {
						itemIds: products[key].id,
						isChecked: !products[key].checked
					}
					checkChange(param).then(res => {
						if (res.code == 0) {
							this.getCartData()
							// this.productData[index].cartProducts[key].checked = !products[key].checked;
							// this.getTotalsum();
						} else {
							uni.showToast({
								title: res.message,
								duration: 1200,
								mask: false,
								icon: 'none'
							});
						}
					})
				} else {
					let ids = []
					this.productData.forEach(item => {
						item.cartProducts.forEach(product => {
							if (product.status === 'onsale')
								ids.push(product.id)
						})
					})
					const param = {
						itemIds: ids.join(),
						isChecked: !this.allChecked
					}
					checkChange(param).then(res => {
						if (res.code == 0) {
							this.getCartData()
							// const checked = !this.allChecked
							// this.productData.forEach(item => {
							// 	item.cartProducts.forEach(product => {
							// 		product.checked = checked;
							// 	})
							// })
							// this.allChecked = checked;
							// this.getTotalsum();
						} else {
							uni.showToast({
								title: res.message,
								duration: 1200,
								mask: false,
								icon: 'none'
							});
						}
					})
				}
			},

			//加减按钮
			NumBtn(type, index, key) {
				if (type === 'plus') {
					this.productData[index].cartProducts[key].num++
				} else {
					this.productData[index].cartProducts[key].num--
				}
				let id = this.productData[index].cartProducts[key].id;
				let num = this.productData[index].cartProducts[key].num
				const param = {
					id: id,
					num: num,
					areaId: uni.getStorageSync('areaId'),
					purchaserId: uni.getStorageSync('deptinfo')[0].deptId
				}
				edit(param).then(res => {
					if (res.code == 0) {
						this.getCartData()
						// this.productData[index].cartProducts[key].num = num
						// this.getTotalsum();
					} else {
						this.$util.msg(res.message)
					}
				})
			},
			editNum(type, number, index, key) {
				let num = parseInt(number);
				if (type === 0) {
					if (num <= 1) {
						return
					}
				}
				num = type === 0 ? (num <= 1 ? num : num - 1) : (num + 1);
				const param = {
					id: this.productData[index].cartProducts[key].id,
					num: num,
					areaId: uni.getStorageSync('areaId'),
					purchaserId: uni.getStorageSync('deptinfo')[0].deptId
				}
				edit(param).then(res => {
					if (res.code == 0) {
						this.getCartData()
						// this.productData[index].cartProducts[key].num = num
						// this.getTotalsum();
					} else {
						this.$util.msg(res.message)
					}
				})
			},
			editInputNum(e, index, key, number) {
				var exceptNum = e.detail.value;
				if (!/^\d*[0-9]\d*$/.test(exceptNum)) {
					this.$util.msg('请填写整数！')
					return;
				}
				if (exceptNum <= 0) {
					exceptNum = 1
					this.productData[index].cartProducts[key].num = 1
				}
				let num = parseInt(exceptNum)
				const param = {
					id: this.productData[index].cartProducts[key].id,
					num: num,
					areaId: uni.getStorageSync('areaId'),
					purchaserId: uni.getStorageSync('deptinfo')[0].deptId
				}
				edit(param).then(res => {
					if (res.code == 0) {
						this.getCartData()
						// this.productData[index].cartProducts[key].num = num
						// this.getTotalsum();
					} else {
						this.$util.msg(res.message)
					}
				})
			},
			//数量
			numberChange(data) {
				const param = {
					id: this.productData[data.index].cartProducts[data.key].id,
					num: data.number
				}
				edit(param).then(res => {
					if (res.code == 0) {
						this.getCartData()
						// this.productData[data.index].cartProducts[data.key].num = data.number;
						// this.getTotalsum();
					} else {
						uni.showToast({
							title: res.message,
							duration: 1200,
							mask: false,
							icon: 'none'
						});
					}
				})
			},
			dianji(index, index1){

				console.log('index1',index1)
				console.log('index',index)
				// console.log('children',children)
				// if(index1 == 1) {
				// 	this.list.splice(index, 1);
				// 	this.$u.toast(`删除了第${index}个cell`);
				// } else {
				// 	this.list[index].show = false;
				// 	this.$u.toast(`收藏成功`);
				// }
			},
			//更新购物车底部徽标
			freshIcons(){
				countCart().then(res => {
					console.log(res)
					if (res > 0) {
						uni.setTabBarBadge({
							index: 2,
							text: res.toString()
						})
					} else {
						uni.removeTabBarBadge({
							index: 2
						})
					}
				})
			},
			onClick(val1,val2,val3){
				console.log('val1',val1);
				console.log('val2',val2);
				// console.log('val3',val3);
				console.log('选中的商品信息',this.selectedGoods);
				if(val3 == '添加收藏'){
					//执行添加收藏夹操作
					console.log('val1',val1);
					this.addCollection(this.selectedGoods)
					this.freshIcons()
				}
				if(val3 == '取消收藏'){
					//执行添加购物车操作
					console.log('val3',val3);
					this.removeOne(this.selectedGoods)
					// this.addCollection(this.selectedGoods)
				}
				if(val2 == 1){
					//执行删除购物车操作
					console.log('删除购物车');
					this.deleteCartItem(this.selectedGoods)

				}
			},
			dianji2(e,children, index, key){
			console.log('children',children)
			console.log('e',e.position)
			},
			//选择添加收藏夹状态
			selectCollectGoods(val){
				console.log('this.productIndex',this.productIndex);
				console.log('this.productKey',this.productKey);
				this.productData[this.productIndex].cartProducts[this.productKey].isCollection = val==1?true:false;
			},
			//添加收藏夹功能
			addCollection(val){
				// console.log('选中的商品',children)
				const param = {
					productId:val
				}
				addCollection(param).then(res => {
					if (res.code === 0) {
						this.$util.msg('添加收藏夹成功')
						this.selectCollectGoods(1)
						// this.deleteGoods(val)

					} else {
						this.$util.msg(res.message)
					}
				})
			},
			//删除购物车内商品方法
			deleteGoods(val){
				console.log('this.productIndex',this.productIndex);
				console.log('this.productKey',this.productKey);
				const data = {
					itemIds: val
				}
				remove(data).then(res => {
					if (res.code == 0) {
						this.getCartData()
						// this.productData[this.productIndex].cartProducts.splice(this.productKey, 1);
						// // if (this.hasLogin) {
						// // 	this.getCartData()
						// // }
						// this.getTotalsum();
					} else {
						this.$util.msg(res.message)
					}
				})
			},
			//原删除
			// deleteCartItem(children, index, key) {
			// 	uni.showModal({
			// 		cancelColor: '#C0C4CC',
			// 		cancelText: '我再想想',
			// 		confirmText: '删除',
			// 		confirmColor: '#fa436a',
			// 		content: `确认删除该商品？`,
			// 		success: (suc) => {
			// 			if (suc.confirm) {
			// 				const data = {
			// 					itemIds: children.id
			// 				}
			// 				remove(data).then(res => {
			// 					if (res.code == 0) {
			// 						this.productData[index].cartProducts.splice(key, 1);
			// 						if (this.hasLogin) {
			// 							this.getCartData()
			// 						}
			// 						this.getTotalsum();
			// 					} else {
			// 						this.$util.msg(res.message)
			// 					}
			// 				})
			// 			}
			// 		}
			// 	})
			// },
			deleteCartItem(val) {
				uni.showModal({
					cancelColor: '#C0C4CC',
					cancelText: '我再想想',
					confirmText: '删除',
					confirmColor: '#fa436a',
					content: `确认删除该商品？`,
					success: (suc) => {
						if (suc.confirm) {
							const data = {
								itemIds: val
							}
							remove(data).then(res => {
								if (res.code == 0) {
									this.getCartData()
									// this.countSku = this.countSku - val.slice(',').length;
									// // this.productData[index].cartProducts.splice(key, 1);
									// this.productData[this.productIndex].cartProducts.splice(this.productKey, 1);
									// // if (this.hasLogin) {
									// // 	this.getCartData()
									// // }
									// this.getTotalsum();
									this.freshIcons()
								} else {
									this.$util.msg(res.message)
								}
							})
						}
					}
				})
			},
			//删除失效商品
			deleteInvalidItem(item, index) {
				let list = this.invalidGoods;
				let row = list[index];
				let id = row.id;
				const data = {
					itemIds: id
				}
				remove(data).then(res => {
					if (res.code == 0) {
						this.invalidGoods.splice(index, 1);
					} else {
						uni.showToast({
							title: res.message,
							duration: 1200,
							mask: false,
							icon: 'none'
						});
					}
				})
				uni.hideLoading();
			},
			//清空
			clearCart() {
				uni.showModal({
					content: '清空购物车？',
					success: (e) => {
						if (e.confirm) {
							let ids = []
							this.productData.forEach(item => {
								item.cartProducts.forEach(product => {
									if (product.status === 'onsale')
										ids.push(product.id)
								})
							})
							const param = {
								itemIds: ids.join()
							}
							remove(param).then(res => {
								if (res.code == 0) {
									this.getCartData()
									//查询购物车 右上角图标信息
									this.freshIcons()

								} else {
									toast(res.message)
								}
							})
						}
					}
				})
			},
			//清空所有失效商品
			clearInvalid() {
				uni.showModal({
					content: '清空所有失效商品？',
					success: (e) => {
						if (e.confirm) {
							let ids = []
							this.invalidGoods.forEach(item => {
								ids.push(item.id)
							})
							const param = {
								itemIds: ids.join()
							}
							remove(param).then(res => {
								if (res.code == 0) {
									this.invalidGoods = [];
								} else {
									this.toast(res.message)
								}
							})
						}
					}
				})
			},
			// 营销活动-多件折扣
			loadDiscount(){
				// 结构 discountList:[activity:activity,rule:{discount,num},goodsList:[],total,discount]
				const data = this.productData
				data.forEach((supplier,supplierIndex)=>{
					if(supplier.checkedCartProducts.length>0){
						const discountList = []
						// 营销活动 多件折扣商品
						const products = supplier.cartProducts.filter(p=>p.checked&&p.activity&&p.activity.type===1&&p.realPrice<p.originalPrice)
						if(products.length>0){
							// 按不同活动
							const actList = [...new Set(products.map(p=>p.activityId))]
							actList.forEach(actId=>{
								const temp = products.filter(p=>p.activityId === actId)
								const activity = temp[0].activity
								let total,discount,totalNum = 0
								if(temp.length>1){
									total = temp.reduce((a,b)=> a.addFloat(b.originalPrice.multipleFloat(b.num)),0)
									discount = temp.reduce((a,b)=> a.addFloat((b.originalPrice.subtractFloat(b.realPrice)).multipleFloat(b.num)),0)
									totalNum = temp.reduce((a,b)=> a+b.num,0)
								}else{
									totalNum = temp[0].num
									total = temp[0].originalPrice.multipleFloat(totalNum)
									discount = (temp[0].originalPrice.subtractFloat(temp[0].realPrice)).multipleFloat(totalNum)
								}
								let rule = activity.ruleList.filter(r=>totalNum>=r.num)
								if(rule.length>0){
									rule = rule.sort((a,b)=>b.num-a.num)
								}
								discountList.push({activity:activity.data,rule:rule[0]||{},goodsList:temp,total:total,discount:discount})
							})
						}
						this.$set(data[supplierIndex],'discountList',discountList)
					}
				})
			},
			//计算总价
			getTotalsum() {
				this.totalsum = 0
				// this.jieyueTotalSum = 0
				this.checkedNum = 0
				this.productData.forEach((item,i) => {
					// let itemCheckedJyjeSubtotal = 0
					        var itemCheckedSubtotal = 0;

					item.cartProducts.forEach(product => {
						if (product.checked && (product.status === 'onsale' || product.status ===
								'notAmount')) {
							this.checkedNum += 1
							this.totalsum = accAdd(filterTwoBitMoney(this.totalsum), filterTwoBitMoney(
								accMul(product.originalPrice, product.num)))
							let currentCheckedSubtotal = accMul(product.realPrice, product.num);
							// let itemCheckedMarkerPriceSubtotal = accMul(product.marketPrice, product.num)
							itemCheckedSubtotal = accAdd(
							              filterTwoBitMoney(itemCheckedSubtotal),
							              filterTwoBitMoney(currentCheckedSubtotal)
							            );
							// if (!isNaN(itemCheckedMarkerPriceSubtotal)) {
							// 	let currentJyjeSubtotal = accSub(
							// 		itemCheckedMarkerPriceSubtotal,
							// 		currentCheckedSubtotal
							// 	);
							// 	if (currentJyjeSubtotal < 0) {
							// 		currentJyjeSubtotal = 0;
							// 	}
								// itemCheckedJyjeSubtotal = accAdd(
								// 	itemCheckedJyjeSubtotal,
								// 	currentJyjeSubtotal
								// );
								// this.jieyueTotalSum = accAdd(
								// 	this.jieyueTotalSum,
								// 	currentJyjeSubtotal
								// );
							// }
						}
					})
					// if (item.cartProducts.length === 0) {
					// 	this.empty = true;
					// 	return;
					// }
					let checked = true;
					item.cartProducts.forEach(item => {
						if (item.checked === false) {
							checked = false;
						}
					})
					this.allChecked = checked;
					this.productData[i].checkedSubtotal = itemCheckedSubtotal;
				})
				// this.loadDiscount()
				this.loadBatchOrderConfFreight()
			},
			//创建订单
			createOrder() {
				if (this.totalsum === 0) {
					this.toast('至少选择一项！')
					return;
				}
				// 起订量校验
				if (this.productData.length > 0) {
					for (let index in this.productData) {
						let productData = this.productData[index]
						for (let indexs in productData.cartProducts) {
							if ((productData.cartProducts[indexs].checked) && (productData.cartProducts[indexs].moq !=
									null) &&
								(productData.cartProducts[indexs].num < productData.cartProducts[indexs].moq) &&
								(productData.cartProducts[indexs].num > 0)) {
								this.toast("未达到起订量！")
								return
							}
						}
					}
				}
				// 开启打样单 校验是否有私域商品
				if(this.sampleApplication && this.checkSample()){
					this.$util.msg('集采商品请提交打样！')
					return
				}
				if (!uni.getStorageSync('areaId')) {
					console.log('地址id',uni.getStorageSync('areaId'));
					uni.showModal({
						title: '提示',
						content: '当前账号无收货地址，请前往添加收货地址',
						confirmText: '立即前往',
						cancelText: '稍后添加',
						success: (suc) => {
							if (suc.confirm) {
								uni.navigateTo({
									url: '/pages/address/address'
								})
							}
						}
					})
					return
				}
				const params = {
					areaId: uni.getStorageSync('areaId'),
					purchaserId: uni.getStorageSync('deptinfo')[0].deptId
				}
				checkSkip(params).then(res => {
					if (res.code === 0) {
						uni.navigateTo({
							url: `/pages/order/createOrder`
						})
					} else {
						this.$util.msg(res.message)
					}
				})
			},
			// 跳转到商品详情
			navToDetail(item) {
				const id = item.id;
				uni.navigateTo({
					url: `/pages/product/product?id=${id}`
				})
			},
			stopPrevent() {}
		}
	}
</script>

<style lang='scss'>

	page {
		background: #f5f5f5;
	}
/* 滑动购物车样式 */
.main{
    width: 90%;
    height: auto;
    margin: 10px auto;
    overflow: hidden
}
.order-item {
    width: 100%;
    display: flex;
    position: relative;
    margin: 10px auto;
    align-items:right ;
    flex-direction: row;
}
.content{
    width: 100%;
    height: 100px;
    margin: 0 auto;
    border: 1px solid #C0C0C0;
    line-height: 100px;
    text-align: center;
}

.remove {
    margin-left:-5%;
    width: 60px;
    height: 100%;
    background-color: #FFCC33;
    color: #FFFFFF;
    position: absolute;
    top: 0;
    right: -60px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
}
.edit{
    width: 60px;
    height: 100%;
    background-color: #FD013E;
    color: white;
    position: absolute;
    top: 0;
    right: -120px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
}
/* ---- */
	.mp-search-box {
		position: sticky;
		left: 0;
		top: 0;
		z-index: 9999;
		width: 100%;
		height: 100rpx;

		text-align: center;
		display: flex;
		flex-direction: column;

		background-color: rgba($color: #f5f5f5, $alpha: 0.8);

		.searchBox {
			display: flex;
			align-items: center;
			padding: 10rpx;
			flex-direction: column;
			justify-content: space-around;
			// margin-top: 90rpx;
			background-color: white;

			.inputBox {
				display: flex;
				background: #fff;
				height: 68rpx;
				width: 98%;
				border-radius: 5px;

				&::before {
					content: " ";
					display: inline-block;
					width: 33rpx;
					height: 33rpx;
					position: relative;
					top: 18rpx;
					left: 305rpx;
					background: url(../../static/search-icon.png) no-repeat;
					background-size: contain;
				}
			}


		}

		.ser-input {
			width: 100%;
			height: 70rpx;
			line-height: 60rpx;
			text-align: center;
			font-size: 28upx;
			color: #909090;
			border-radius: 5px;
			// background: #f0f0f0;
			// background: #fff;
		}

		.search {
			width: 40rpx;
			height: 40rpx;
			margin-top: 10rpx;
		}

		.ph {
			text-align: center;
			font-size: 28upx;
			color: $font-color-base;
		}
	}

	.container {
		background-color: #f5f5f5;
		padding-bottom: 200rpx;

		.loading-container {
			text-align: center;
			padding-top: 20px;
		}

		/* 空白页 */
		.empty {
			/* position: fixed; */
			left: 0;
			top: 0;
			width: 100%;
			padding-top: 40rpx;
			/* height: 100%; */
			/* padding-bottom: 100upx; */
			/* display: flex;
			justify-content: center;
			flex-direction: column;
			align-items: center;
			background: #fff; */

			image {
				width: 240upx;
				height: 160upx;
				margin-bottom: 30upx;
			}

			.empty-tips {
				/* display: flex; */
				text-align: center;
				font-size: $font-sm+2upx;
				color: $font-color-disabled;

				.navigator {
					color: $uni-color-primary;
					margin-left: 16upx;
				}
			}
		}
	}



	.invalid-btn {
		margin-right: 16px;
		background: #c7c7c7;
		border: 1px solid #c7c7c7;
		border-radius: 4px;
		color: #ffffff;
		padding-left: 7px;
		padding-right: 7px;
		padding-top: 5px;
		padding-bottom: 5px;
		float: right;
		text-align: center;
		font-size: 10px;
	}


	.image-container {
		width: 160upx;
		height: 160upx;
		flex-shrink: 0;
		position: relative;

		image {
			border-radius: 8upx;
			width: 160upx;
			height: 160upx;
			/* background-color: #e2e2e2; */
			background: url(../../static/error-img-115.png);
		}
	}

	.c-item {
		margin: 20rpx;
		background-color: #fff;
		border-radius: 20rpx;
		padding-top: 20rpx;
	}

	.protocol-box {
		display: flex;
		align-items: center;
		padding: 0 20upx;

		.protocol-box-left{
			display: flex;
			flex: 1;
			width: 0;
		}
	}

	.logo {
		width: 36upx;
		height: 36upx;
		padding-right: 10upx;
	}

	.protocol {
		font-size: $font-base;
		flex: 1;
		word-break: break-all;
		/* font-weight: bold; */
	}

	.wrapper {
		padding: 20rpx;

		.a-section {
			margin-top: 20rpx;
			display: flex;
			align-items: center;
			text-align: center;

			.a-tit {
				font-size: 26rpx;
			}

			.activity {
				font-size: 24rpx;
				color: #e90000;
				border-radius: 4rpx;
				margin-right: 10rpx;
				padding: 0 8rpx;
				border: 1rpx solid #e90000;
			}
		}

	}

	/* 购物车列表项 */
	.cart-item {
		display: flex;
		position: relative;
		margin-top: 10upx;

		.image-wrapper {
			width: 160upx;
			height: 160upx;
			flex-shrink: 0;
			position: relative;

			image {
				border-radius: 8upx;
			}
			.soldout {
				position: absolute;
				left: 0;
				top: 0;
				width: 160upx;
				height: 160upx;
				z-index: 94;
			}
		}

		.checkbox {
			position: absolute;
			left: -16upx;
			top: -16upx;
			z-index: 8;
			font-size: 44upx;
			line-height: 1;
			padding: 4upx;
			color: $font-color-disabled;
			background: #fff;
			border-radius: 50px;
		}

		.item-right {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			flex: 1;
			overflow: hidden;
			position: relative;
			padding-left: 30upx;

			.title {
				max-width: 180px;
				color: $font-color-dark;
				font-size: $font-base + 2upx;
				overflow: hidden;
				text-overflow: ellipsis;
			}

			/*多行文本溢出省略号*/
			.more-t {
				overflow: hidden; // 超出的文本隐藏
				word-break: break-all;
				text-overflow: ellipsis; // 溢出用省略号显示
				display: -webkit-box; // 将对象作为弹性伸缩盒子模型显示。
				-webkit-line-clamp: 2; // 这个属性不是css的规范属性，需要组合上面两个属性，表示显示的行数。
				-webkit-box-orient: vertical; // 从上到下垂直排列子元素（设置伸缩盒子的子元素排列方式）
				transition: all linear 0.2s;
			}

			.price {
				/* font-size: $font-base + 4upx; */
				font-size: $font-middle;
				color: $uni-color-primary;
				/* height: 40upx; */
				/* 	position: absolute;
				left: 15px;
				bottom: 55px; */
				line-height: 40upx;
			}

			.discount{
				background-color: #fff6f5;
				font-size: $font-middle;
				width: fit-content;
				color: #e90000;
				border-radius: 4rpx;
				padding: 4rpx 8rpx;
			}

			.attr {
				font-size: $font-sm + 2upx;
				color: $font-color-light;
				height: 50upx;
				line-height: 50upx;
			}

			.uni-num-box {
				display: flex;
				margin-right: 3px;

				.add,
				.subtract {
					display: flex;
					align-items: center;
					justify-content: center;
					width: 60rpx;
					height: 60rpx;
					color: #333;
					font-size: 40rpx;
					border: 1rpx solid #e5e5e5;
					background-color: #f8f8f8;

					&.disabled {
						color: $font-color-disabled;
					}
				}

				.count {
					display: flex;
					align-items: center;
					width: 100rpx;
					height: 60rpx;
					line-height: 50rpx;
					font-size: 14px;
					text-align: center;
					border-top: 1rpx solid #e5e5e5;
					border-bottom: 1rpx solid #e5e5e5;
					background-color: #fff;
				}

				.stack {
					color: #dd524d;
					padding-top: 6px;
					padding-left: 3px;
				}
			}
		}

		.del-btn {
			padding: 4upx 10upx;
			font-size: 34upx;
			height: 50upx;
			color: $font-color-light;
		}
	}

	.gray {
		color: #909399;
	}

	/* 底部栏 */
	.action-section {
		/* #ifdef H5 */
		margin-bottom: 100upx;
		/* #endif */
		position: fixed;
		left: 20upx;
		right: 20rpx;
		bottom: 30upx;
		z-index: 95;
		/* width: 690upx; */
		height: 150upx;
		padding: 10rpx 20upx;
		background: rgba(255, 255, 255, .9);
		box-shadow: 0 0 20upx 0 rgba(0, 0, 0, .5);
		border-radius: 16upx;
		display: flex;
		align-items: center;

		.checkbox {
		/* 	height: 52upx;
			position: relative; */
			display: flex;
			align-items: center;

			image {
				width: 52upx;
				height: 52rpx;
				/* position: relative; */
				z-index: 5;
			}
		}

		.clear-btn {
			/* position: absolute; */
			/* left: 26upx;
			top: 0; */
			margin-left: -26rpx;
			z-index: 4;
			width: 0;
			height: 52upx;
			line-height: 52upx;
			padding-left: 38upx;
			font-size: $font-base;
			color: #fff;
			background: $font-color-disabled;
			border-radius: 0 50px 50px 0;
			opacity: 0;
			transition: .2s;

			&.show {
				opacity: 1;
				width: 120upx;
			}
		}

		.total-box-left{
			display: flex;
			align-items: center;
		}

		.total-box {
			flex: 1;
			text-align: right;
			margin-right: 20rpx;
			font-size: $font-sm;

			.price {
				font-size: $font-base + 4upx;
				color: $uni-color-primary;
			}

			.coupon {
				font-size: $font-sm;
				color: $uni-color-primary;
			}
		}

		.confirm-btn {
			padding: 0 38upx;
			margin: 0;
			border-radius: 100px;
			height: 76upx;
			line-height: 76upx;
			font-size: $font-base + 2upx;
			background: $uni-color-primary;
			box-shadow: 1px 2px 5px rgba(217, 60, 93, 0.72)
		}
	}

	/* 复选框选中状态 */
	.action-section .checkbox.checked,
	.cart-item .checkbox.checked {
		color: $uni-color-primary;
	}
</style>
